package com.ruoyi.web.controller.teacher;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.teacher.domain.MyTask;
import com.ruoyi.teacher.service.IMyTaskService;
import com.ruoyi.teacher.vo.MyTaskVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我的任务Controller
 *
 * @author TengZeng
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/mytask")
public class MyTaskController extends BaseController
{
    @Autowired
    private IMyTaskService myTaskService;

    /**
     * 查询我的任务列表
     */
    @PreAuthorize("@ss.hasPermi('task:mytask:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyTask myTask)
    {
        startPage();
        List<MyTask> list = myTaskService.selectMyTaskList(myTask);
        return getDataTable(list);
    }

    /**
     * 添加完成
     * @param vo
     * @return
     */
    @PutMapping("/toFinish")
    public AjaxResult toFinish(@RequestBody MyTaskVo vo) {
        return success(myTaskService.toFinish(vo));
    }


    /**
     * 导出我的任务列表
     */
    @PreAuthorize("@ss.hasPermi('task:mytask:export')")
    @Log(title = "我的任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyTask myTask)
    {
        List<MyTask> list = myTaskService.selectMyTaskList(myTask);
        ExcelUtil<MyTask> util = new ExcelUtil<MyTask>(MyTask.class);
        util.exportExcel(response, list, "我的任务数据");
    }

    /**
     * 获取我的任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:mytask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(myTaskService.selectMyTaskById(id));
    }

    /**
     * 新增我的任务
     */
    @PreAuthorize("@ss.hasPermi('task:mytask:add')")
    @Log(title = "我的任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyTask myTask)
    {
        return toAjax(myTaskService.insertMyTask(myTask));
    }

    /**
     * 修改我的任务
     */
    @PreAuthorize("@ss.hasPermi('task:mytask:edit')")
    @Log(title = "我的任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyTask myTask)
    {
        return toAjax(myTaskService.updateMyTask(myTask));
    }

    /**
     * 删除我的任务
     */
    @PreAuthorize("@ss.hasPermi('task:mytask:remove')")
    @Log(title = "我的任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myTaskService.deleteMyTaskByIds(ids));
    }

    /**
     * 删除我的任务
     */
    @DeleteMapping
    public AjaxResult delete(@RequestBody MyTaskVo vo)
    {
        return toAjax(myTaskService.deleteMyTaskById(vo));
    }
}
